package com.ruyuan.commodity.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruyuan.commodity.model.goods.dos.DraftGoodsParamsDO;
import com.ruyuan.commodity.model.goods.vo.GoodsParamsVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * DraftGoodsParams的Mapper
 */
@Repository
public interface DraftGoodsParamsMapper extends BaseMapper<DraftGoodsParamsDO> {

    /**
     * 查询草稿商品关联的参数及参数值
     * @param categoryId 分类id
     * @param draftGoodsId 草稿商品id
     * @return
     */
    @ResultType(GoodsParamsVO.class)
    @Select("<script>" +
                "select p.*,gp.param_value,p.group_id  from es_parameters p  left join es_draft_goods_params gp on p.param_id=gp.param_id " +
                "<where>" +
                "  p.category_id = #{category_id} and (gp.draft_goods_id = #{draft_goods_id}  or gp.draft_goods_id is null) " +
                "</where>" +
            "</script>")
    List<GoodsParamsVO> queryDraftGoodsParamsValue(@Param("category_id") Long categoryId, @Param("draft_goods_id") Long draftGoodsId);
}
